<?php
namespace Home\Controller;
use Think\Controller;
use Com\Wechat;
use Com\WechatAuth;
class WeiController extends Controller {
    public function index(){
        $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }
    
    public function Wei(){
 //echo $_SERVER["QUERY_STRING"]."<br>";
 $code=$_REQUEST['code'];
     $token = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxc19f94ce488d17d2&secret=d75619b22d53b7c2d8a9c3d1ca18203a&code =$code&grant_type=authorization_code");
        $shuzhu = json_decode($token);
        $arry = get_object_vars( $shuzhu);
        var_dump($token);die;
        $opeid= $arry['openid'];
        $access_token=$arry['access_token'];
        $weixin = file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN");
        $jsondecode= json_decode($weixin);
        $array = get_object_vars($jsondecode);
        $nickname = $array['nickname'];
        $headimgurl = $arry['headimgurl'];
        
        $this->assign('array',$array);
    }

    public function Xin(){
        
        
        $data = ' {  
             "button":[  
             {    
                  "type":"view",  
                  "name":"今日歌曲",  
                  "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6cfdf33c11a83c3d&redirect_uri=http://hejiajun.vicp.io/weixin.php&response_type=code&scope=snsapi_userinfo&&state=STATE#wechat_redirect"  
              },  
              {  
                   "type":"view",  
                   "name":"歌手简介",  
                   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6cfdf33c11a83c3d&redirect_uri=http://hejiajun.vicp.io/weixin.php&response_type=code&scope=snsapi_userinfo&&state=STATE#wechat_redirect"  
              },  
              {  
                   "name":"菜单",  
                   "sub_button":[  
                   {      
                       "type":"view",  
                       "name":"搜索",  
                       "url":"http://www.soso.com/"  
                    },  
                    {  
                       "type":"view",  
                       "name":"视频",  
                       "url":"http://v.qq.com/"  
                    },  
                    {  
                       "type":"click",  
                       "name":"赞一下我们",  
                       "key":"V1001_GOOD"  
                    }]  
               }]  
         }';  
  
         $ch = curl_init();  
         curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=YLfIFZJIfKHsYScOxiIjsQBoiWd_4T-ZkfbXkmjfFHFlYBxys3IG6UYhs-wcCTvMcEyu8QoQcapl7amOpEfVN9F5_sSDpBBJlB-7oLum-CodpsFXVR8_UoSBOrw6ZbuTXUMdAHAMJB");  
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');  
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
         curl_setopt($ch, CURLOPT_AUTOREFERER, 1);  
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
         $tmpInfo = curl_exec($ch);  
         if (curl_errno($ch)) {  
          echo curl_error($ch);  
         }  
          
         curl_close($ch);                                       
            
        echo $tmpInfo;  
        $this->display();
    }
   
}